package com.bookcode.service;


import com.bookcode.dao.SignRepository;
import com.bookcode.entity.Sign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class SignService {

    @Autowired
    SignRepository signRepository;
    //根据id选择签到码信息
    public Sign findSignById(Long id){
        return signRepository.findById(id).get();
    }
    //插入一条签到码
    public void save(Sign sign){
        signRepository.save(sign);
    }
    //通过课程号 找到一条最新的签到码
    public Sign findSignsByCourse(String courseId){
        return signRepository.findSignCodeByCourseId(courseId);
    }
    //停止课程为courseId的课程签到
    public void stopSign(String courseId){
        signRepository.undateState(courseId);
    }

//    public Boolean signIsEnd(Long id){
//        return signRepository.findById(id).get().getEnd();
//    }

//    public List<Sign> findSignsNotEndByCourse(Long courseId){
//        return signRepository.findSignsNotEndByCourse(courseId);
//    };
}
